package cn.stronglink.asset.module.index.controller;

import java.util.HashMap;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import cn.stronglink.asset.module.alarm.service.AlarmService;
import cn.stronglink.asset.module.assetmanage.instock.service.PresetService;
import cn.stronglink.asset.module.assetmanage.itasset.service.ItassetService;
import cn.stronglink.asset.module.assetmanage.scrap.service.ScrapService;
import cn.stronglink.asset.module.basicdata.tRoom.service.TRoomService;
import cn.stronglink.suite.core.base.AbstractController;

@Controller
@RequestMapping(value = "")
public class IndexController extends AbstractController {

	@Autowired
	private TRoomService tRoomService;
	@Autowired
	private ItassetService itassetService;
	@Autowired
	private AlarmService alarmService;
	@Autowired
	private ScrapService scrapService;
	@Autowired
	private PresetService presetService;

	/**
	 * 机房总数
	 * @param modelMap
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "roomCount")
	public ResponseEntity<ModelMap> roomCount(ModelMap modelMap, HttpServletRequest request,
			HttpServletResponse response) {	
		int roomCount =tRoomService.qryRoomCount();//机房总数	
		int rackCount =itassetService.qryRackCount();	
		modelMap.put("rackCount", rackCount);
		return setSuccessModelMap(modelMap, roomCount);
	}
	/**
	 * U位总数
	 * @param modelMap
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "qryUcount")
	public ResponseEntity<ModelMap> qryUcount(ModelMap modelMap, HttpServletRequest request,
			HttpServletResponse response) {	
		int uCount =itassetService.qryUcount();//U位总数
		return setSuccessModelMap(modelMap, uCount);
	}
	/**
	 * 设备总数
	 * @param modelMap
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "qryAssetCount")
	public ResponseEntity<ModelMap> qryAssetCount(ModelMap modelMap, HttpServletRequest request,
			HttpServletResponse response) {
		int assetCount =itassetService.qryAssetCount();//设备总数
		return setSuccessModelMap(modelMap, assetCount);
	}
	/**
	 * 异常报警总数量    
	 * @param modelMap
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "qryAlarmCount")
	public ResponseEntity<ModelMap> qryAlarmCount(ModelMap modelMap, HttpServletRequest request,
			HttpServletResponse response) {	
		int alarmCount =alarmService.qryAlarmCount();//异常报警总数量
		return setSuccessModelMap(modelMap, alarmCount);
	}
	/**
	 *预置资产设备 //机房设备分布
	 * @param modelMap
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "qryPresetCount")
	public ResponseEntity<ModelMap> qryPresetCount(ModelMap modelMap, HttpServletRequest request,
			HttpServletResponse response) {	
		int presetCount =presetService.qryPresetCount();//预置资产设备
		//机房设备分布
		List<HashMap<String,Object>> roomData = itassetService.qryAssetPerGroupByRoom();
		modelMap.put("roomData", roomData);
		return setSuccessModelMap(modelMap, presetCount);
	}
	/**
	 * 机房U位使用情况
	 * @param modelMap
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "qryUPerByRoom")
	public ResponseEntity<ModelMap> qryUPerByRoom(ModelMap modelMap, HttpServletRequest request,
			HttpServletResponse response) {
		List<HashMap<String,Object>> uData = itassetService.qryUPerGroupByRoom();
		return setSuccessModelMap(modelMap, uData);
	}
	
	/**
	 * 即将报废的设备
	 * @param modelMap
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "qryScrapCount")
	public ResponseEntity<ModelMap> qryScrapCount(ModelMap modelMap, HttpServletRequest request,
			HttpServletResponse response) {	
		int scrapCount =scrapService.qryScrapCount();//即将报废的设备
		return setSuccessModelMap(modelMap, scrapCount);
	}
	
	
	
	/**
	 * 机房资产分类数据显示
	 * @param modelMap
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "assetCountByRoom")
	public ResponseEntity<ModelMap> assetCountByRoom(ModelMap modelMap, HttpServletRequest request,
			HttpServletResponse response,@RequestBody Long roomId) {	
		List<HashMap<String,Object>> data = itassetService.qryAssetCountByRoom(roomId);//按机房统计每种设备类型有多少个设备
		int total =0;
		if(data!=null&&data.size()>0){
			for(HashMap<String,Object> map :data){
				total+=Integer.parseInt(map.get("value").toString());
			}
		}
		modelMap.put("total", total);
		return setSuccessModelMap(modelMap, data);
	}
	
}
